home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Developer Utilities / Installer 4.0.3 SDK / Script Examples / Search Proc [insp] Example / myFileSearchProc.r < prev    next >
Encoding:
Text File  |  1994-11-15  |  11.9 KB  |  416 lines  |  [TEXT/MPS ]

  1. //
  2. //    myFileSearchProc.r
  3. //        
  4. //    The example file search proc uses TYPE and CREATOR to determine 
  5. //    list of matching files on target volume, rather than searching on filename.
  6. //    Your search procedure ( code segment ) can use any approach that you wish.
  7. //    We have chosen a relatively simple method for sake of simplicity. Our search
  8. //    procedure example does not exclude files in the trash or files in any
  9. //    installer temp folders that might exist in the system folder of the 
  10. //    target volume. 
  11. //
  12. //    Extra 'vers' resources of ID # (3) and (4) have been added to the source 
  13. //    "TeachText" file contained within subfolder "Disk 1:" so that the "original" 
  14. //    and "replaced" copies of "TeachText" ( on target volume )
  15. //    can be distinguished from each other.
  16. //
  17. //    Search procedures can be used to select files to be replaced, or can
  18. //    be used within the rule framework to add Easy Install or Custom Install
  19. //    packages depending on whether or not a file exists on the target volume.
  20. //    Search procedures can also be used within the rule framework to display
  21. //    an error message, warning the user that installation cannot be performed
  22. //    to the selected target volume because a certain file does not exist on
  23. //    the target volume. This feature is especially useful when performing
  24. //    upgrades of application or system software.
  25. //
  26. //    IMPORTANT: With Installer 4.0.3 the only atoms that support the file 
  27. //    search procedure are file ( 'infa' ) and resource ( 'inra' ) atoms. The 
  28. //    FolderMerge ( 'infm' ) and ResMerge ( 'inrm' ) atoms are not supported.
  29. //    Even if one of the unsupported atoms uses a target spec ( 'intf' ) that 
  30. //    includes a file search proc, the normal file search mechanism will be
  31. //    used when processing the unsupported atom.
  32. //
  33. //    There are four packages in this example script. Each package utilizes
  34. //    a sample file search procedure that overrides the default search path
  35. //    for Installer 4.x. Each package generates one custom install option 
  36. //    for each of the following example cases:
  37. //
  38. //    1) file atom - delete on install, copy on install
  39. //
  40. //        This option first deletes all found copies of "TeachText" and "SimpleText"
  41. //        ( as well as any other files with Type 'APPL' and Creator 'ttxt' )
  42. //        from the target volume ( making backups to "InstallerTemp:" during
  43. //        live-install ), then copies the "TeachText" application contained in the
  44. //        subfolder "Disk 1:" to the target volume to replace all found copies
  45. //        of "TeachText" and "SimpleText". 
  46. //
  47. //    2) file atom - delete on install, but don't copy on install
  48. //
  49. //        This option deletes all found copies of "TeachText" and "SimpleText"
  50. //        ( as well as any other files with Type 'APPL' and Creator 'ttxt' )
  51. //        from the target volume ( making backups to "InstallerTemp:" during
  52. //        live-install ). 
  53. //
  54. //    3) resource atom - delete on install, copy on install
  55. //
  56. //        This option first deletes the resource 'vers' (3) from all found
  57. //        copies of "TeachText" and "SimpleText" ( as well as any other files 
  58. //        with Type 'APPL' and Creator 'ttxt' ) on the target volume ( making 
  59. //        backups to "InstallerTemp:" during live-install ), then copies the 
  60. //        'vers' (3) resource item from within the "TeachText" application 
  61. //        contained in the subfolder "Disk 1:" to each copy of "TeachText"
  62. //        and "SimpleText" found on the target volume.
  63. //
  64. //    4) resource atom - delete on install, but don't copy on install
  65. //
  66. //        This option deletes the resource 'vers' (3) from all found
  67. //        copies of "TeachText" and "SimpleText" on the target volume ( making 
  68. //        backups to "InstallerTemp:" during live-install ).
  69. //
  70. //
  71. //
  72. //        mark young • 08/17/94
  73. //
  74. //        Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
  75. //
  76.  
  77. #include "InstallerTypes.r"
  78.  
  79. // include the 'infn' code resource containing file searching procedure
  80. include "FindTargetFile.rsrc";
  81.  
  82.  
  83.  
  84. // • framework and rules
  85.  
  86. // custom install framework always uses ID# 766
  87.  
  88. // Custom Install framework fires both rules listed below
  89. resource 'infr' ( kCustomInstallFrameworkRsrcID ) {
  90.     format0 {{
  91.         pickAll, { 100,500 },
  92.     }}
  93. };
  94.  
  95. // add the first four custom install packages
  96. resource 'inrl' ( 100 ) {
  97.     format0 {{
  98.         AddCustomItems {{ 100,200,300,400 }}            
  99.     }};
  100. };
  101.  
  102. // reference 'insp' ( file search proc ) 
  103. // contained within 'intf' ( target file spec )
  104. resource 'inrl' ( 500 ) {
  105.     format0 {{
  106.         checkFileRsrcForkExists { 10001 },    // add the last package only if
  107.         AddCustomItems {{ 500 }}            // the rule above returned true
  108.     }};
  109. };
  110.  
  111.  
  112. // • packages
  113.  
  114. // package for file search proc
  115. // w/ file atoms - delete on install, copy on install
  116. resource 'inpk' (100) {
  117.     format0 {
  118.         showsOnCustom,
  119.         removable,
  120.         dontForceRestart,
  121.         0,
  122.         0,
  123.         "Remove, then Replace all copies of “TeachText” on target volume.",
  124.         {    
  125.         'infa', 1000    
  126.         },
  127.     }
  128. };
  129.  
  130. // package for file search proc
  131. // w/ file atoms - delete on install, but don't copy on install
  132. resource 'inpk' (200) {
  133.     format0 {
  134.         showsOnCustom,
  135.         removable,
  136.         dontForceRestart,
  137.         0,
  138.         0,
  139.         "Remove all copies of “TeachText” on target volume.",
  140.         {    
  141.         'infa', 2000    
  142.         },
  143.     }
  144. };
  145.  
  146.  
  147. // package for file search proc
  148. // w/ resource atoms - delete on install, copy on install
  149. resource 'inpk' (300) {
  150.     format0 {
  151.         showsOnCustom,
  152.         removable,
  153.         dontForceRestart,
  154.         0,
  155.         0,
  156.         "Add/Replace 'vers' (4) resource to all copies of “TeachText” on tgt vol.",
  157.         {    
  158.         'inra', 3000    
  159.         },
  160.     }
  161. };
  162.  
  163.  
  164. // package for file search proc
  165. // w/ resource atoms - delete on install, but don't copy on install
  166. resource 'inpk' (400) {
  167.     format0 {
  168.         showsOnCustom,
  169.         removable,
  170.         dontForceRestart,
  171.         0,
  172.         0,
  173.         "Remove 'vers' (4) resource from all copies of “TeachText” on tgt vol.",
  174.         {    
  175.         'inra', 4000    
  176.         },
  177.     }
  178. };
  179.  
  180. // this last package just provides an easy way to see if the
  181. // second rule in the Custom Install framework returned true.
  182.  
  183. // package for file search proc
  184. // utilizes 'insp' from within installer rule framework
  185. resource 'inpk' (500) {
  186.     format0 {
  187.         showsOnCustom,
  188.         notRemovable,
  189.         dontForceRestart,
  190.         0,
  191.         0,
  192.         "Rule calling 'insp' via 'intf' succeeded ( or I'd not be here ) !!",
  193.         {    
  194.         'infa', 1000    
  195.         },
  196.     }
  197. };
  198.  
  199. // • file atoms
  200.  
  201. // file atom for file seach proc, remove and replace during install
  202. resource 'infa' (1000) {
  203.     format1 {
  204.         deleteWhenRemoving,
  205.         deleteWhenInstalling,
  206.         copy,                        
  207.         dontIgnoreLockedFile,
  208.         dontSetFileLocked,
  209.         useVersProcToCompare,        
  210.         srcNeedExist,
  211.         rsrcForkInRsrcFork,
  212.         leaveAloneIfNewer,            
  213.         updateExisting,                
  214.         copyIfNewOrUpdate,
  215.         rsrcFork,
  216.         dataFork,
  217.         0,
  218.         0x0,
  219.         10001,
  220.         {    
  221.             10000, 
  222.             0, 
  223.             0    
  224.         },
  225.         0,                        
  226.         0,
  227.         0,
  228.         "TeachText"
  229.     }
  230. };
  231.  
  232. // file atom for file seach proc, remove but don't copy during install
  233. resource 'infa' (2000) {
  234.     format1 {
  235.         deleteWhenRemoving,
  236.         deleteWhenInstalling,
  237.         dontCopy,                    //  • don't Copy during Install
  238.         dontIgnoreLockedFile,
  239.         dontSetFileLocked,
  240.         useVersProcToCompare,        //  Use version proc for compare
  241.         srcNeedExist,
  242.         rsrcForkInRsrcFork,
  243.         leaveAloneIfNewer,            //  Do not update a newer file
  244.         updateExisting,                //  Update an existing file
  245.         copyIfNewOrUpdate,
  246.         rsrcFork,
  247.         dataFork,
  248.         0,
  249.         0x0,
  250.         10001,
  251.         {    
  252.             10000, 
  253.             0, 
  254.             0    
  255.         },
  256.         0,                            
  257.         0,
  258.         0,
  259.         "TeachText"
  260.     }
  261. };
  262.  
  263. // • resource atoms
  264.  
  265. // resource atom for file seach proc; remove, copy during install
  266. resource 'inra' (3000) {
  267.     format1 {
  268.         deleteWhenRemoving,
  269.         deleteWhenInstalling,
  270.         copy,                        // Copy during Install
  271.         leaveAloneIfNewer,            // Do not update a newer file
  272.         tgtRequired,                // Don't allow install unless target exists
  273.         updateExisting,                // Update an existing file
  274.         copyIfNewOrUpdate,            // Make or replace
  275.         dontIgnoreProtection,        // Respect those protected bits
  276.         srcNeedExist,                // Source must exist on install disk
  277.         
  278.         byID,                        // Reference resource by ID #
  279.         nameNeedNotMatch,            // Only use ID # for target of resource
  280.         
  281.         0,                             
  282.         10001,                        // Target file spec
  283.         'vers',                        // Target resource type
  284.         4,                            // Target resource ID #
  285.         0x0,                        // Target resource attributes
  286.         "resource search proc",        // Target resource name
  287.         {
  288.             10000,                    // Source file spec
  289.             'vers',                    // Source piece type
  290.             4,                        // Source piece ID #
  291.             0,                        // Target piece size
  292.             "",                        // Source piece resource name
  293.         },
  294.         0x0,                        // Source version #
  295.         0,                            // Version compare resource number
  296.         0,                            // Atom extender resource ID
  297.         ""                            // Total target size
  298.     }
  299. };
  300.  
  301.  
  302. // resource atom for file seach proc; remove, but don't copy during install
  303. resource 'inra' (4000) {
  304.     format1 {
  305.         deleteWhenRemoving,
  306.         deleteWhenInstalling,
  307.         dontCopy,                    // Don't copy during Install
  308.         leaveAloneIfNewer,            // Do not update a newer file
  309.         tgtRequired,                // Don't allow install unless target exists
  310.         updateExisting,                // Update an existing file
  311.         copyIfNewOrUpdate,            // Make or replace
  312.         dontIgnoreProtection,        // Respect those protected bits
  313.         srcNeedExist,                // Source must exist on install disk
  314.         byID,                        // Reference resource by ID #
  315.         nameNeedNotMatch,            // Existing resource referenced by ID # 
  316.                                     // must have same name to be replaced.
  317.         0,                             
  318.         10001,                        // Target file spec
  319.         'vers',                        // Target resource type
  320.         4,                            // Target resource ID #
  321.         0x0,                        // Target resource attributes
  322.         "resource search proc",        // Target resource name
  323.         {
  324.             10000,                    // Source file spec
  325.             'vers',                    // Source piece type
  326.             4,                        // Source piece ID #
  327.             0,                        // Target piece size
  328.             "",                        // Source piece resource name
  329.         },
  330.         0x0,                        // Source version #
  331.         0,                            // Version compare resource number
  332.         0,                            // Atom extender resource ID
  333.         ""                            // Total target size
  334.     }
  335. };
  336.  
  337.  
  338. // • file specs
  339.  
  340. // target file spec for file search atom
  341. resource 'intf' (10001) {
  342.     format1 {
  343.         searchForFile,                    // • override default search path
  344.         
  345.         TypeCrMustMatch,                 // If this is set to TypeCrMustMatch
  346.                                         // then a file with a different type
  347.                                         // and creator than those specified
  348.                                         // below will not be replaced.
  349.                                         // If this is set to TypeCrNeedNotMatch
  350.                                         // then type and creator of an existing
  351.                                         // target file are ignored.
  352.         
  353.         // The Type and Creator fields will be used to set the
  354.         // file's Type and Creator when a new file is created. 
  355.         'APPL',                         // TYPE for new file
  356.         'ttxt',                         // CREATOR for new file
  357.         
  358.         0,                                 // finder attribute flags
  359.                                         // filled by ScriptCheck is value is 0
  360.         
  361.         1,                                  // creation date for new file
  362.         1,                                  // modification date for new file
  363.                                         // NOTE: DATE values are filled
  364.                                         // by ScriptCheck if the value is 1
  365.                                             
  366.         200,                            // • 'insp' resource ID ( file search proc )
  367.         
  368.         ":TeachText"                    // path to target file
  369.         }
  370.     };
  371.  
  372. // source file spec for file search atom
  373. resource 'infs' (10000) {
  374.     'APPL',                        // TYPE for source file
  375.     'ttxt',                        // CREATOR for source file
  376.     0x1,                        // creation DATE for source file
  377.     searchForFile,                // IGNORED in Installer 4.0.x
  378.     TypeCrMustMatch,            // TYPE, CREATOR must match file on install disk
  379.     "Disk 1:TeachText"            // PATH to source file        
  380. };
  381.  
  382.  
  383. // • interface to search proc
  384.  
  385. // file search proc
  386. resource 'insp' (200) {
  387.     format0 {
  388.         'infn',                    // SEARCH PROC • Code Rsrc Type
  389.         20,                        // SEARCH PROC • Code Rsrc ID
  390.                                 // NOTE: The code resource type and ID
  391.                                 // values are specified within the makefile 
  392.                                 // for the search proc code resource. 
  393.                                 // In this example the lines that create the 
  394.                                 // search proc code resource are in the same 
  395.                                 // makefile as the one that builds the installer 
  396.                                 // script. You should use the values specified 
  397.                                 // in the makefile to fill in these fields.
  398.                                 
  399.         0,                        // SEARCH PROC • RefCon
  400.                                 // NOTE: This value will be passed
  401.                                 // into your search proc code resource
  402.                                 // when the search procedure is called.
  403.                                 
  404.         0,                        // SEARCH PROC • Min Required Memory
  405.                                 // NOTE: Set this value to 0 to use
  406.                                 // the installer's allocate memory.
  407.                                 // Unless your search proc code resource
  408.                                 // has specific need for its own memory
  409.                                 // heap you should always set this
  410.                                 // value to 0.
  411.                                 
  412.         "Searching for all files."    
  413.                                 // SEARCH PROC • Description
  414.     }
  415. };
  416.